// ==UserScript==
// @name 10086gq
// @author wgu
// @description  10086gq
// @include http://f.10086.cn/guoqing/*
// @include http://f.10086.cn/nuc/user/guoqing/login.do*
// ==/UserScript==
gw.import('post.js',window);
(function($){	
	
	$.net.config={
		'sendURL':'http://f.10086.cn/guoqing/tosend.do',
		'lockURLT':'http://bbs.2500sz.com/bbs/forum.php?mod=redirect&tid={#tid}&goto=lastpost',
		'lockT':10000,
		'lookT':3000,
		'lookfl':50,
		'sendfl':7,
		'_reloadT':2000,
		'_nextT':500,
		'ckManage':gw.ckManage(["f.10086.cn/","f.10086.cn/guoqing"]),
		'getfl':function(t){ 
					return 10;
				}
	}
		
	var req=new XMLHttpRequest(),req2 = gw.req(),hostname=location.hostname;
	var panel=jQuery.net.cache,convert=gw.convert,ob=gw.ob,cookie=gw.cookie,ckManage=jQuery.net.config.ckManage;
	$.net.useInfo._init=function(obj){
		ckManage.remove();
		
		var url='http://f.10086.cn/nuc/user/guoqing/login.do?m=submit&backurl=http://f.10086.cn/guoqing/open.do&fr=guoqing'
			,data='mobilenum={#userId}&password={#passWord}';
		req.open('POST', url, false);
		req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		req.send(data.format(obj));
		
		url=/ontimer="([^"]+)/g.exec(req.responseText)[1];
		req.open('GET', url, false);
		req.send(null);
		
		obj.nuc_id=url.replace('http://f.10086.cn/guoqing/open.do?nuc_id=','');		
		obj.cookie=ckManage.get();
		
		return this;
	}	
	
	jQuery.net.panel._panel=function (x,button){
		var html=[],t1='<option value="{#i}">{#name}</option>';
		var useInfos=jQuery.net.cache.useInfos,x=x||"";
		for(var i in useInfos){
			if(useInfos[i].name==x){
				html.unshift(t1.format({'i':i,'name':useInfos[i].name}));
			}else{
				html.push(t1.format({'i':i,'name':useInfos[i].name}));
			}
			jQuery.net.reqInfos[useInfos[i].userId]={'time':0,'req':new XMLHttpRequest()};
		}

		if(jQuery("#wgu_tool").length==0){
			jQuery('<div id="wgu_tool" style="bottom:0px;border-width: 1px;position: fixed;border-style: solid;border-radius: 11px 11px 0px 0px;padding:5px;background-color:White;">'
				+'<div><select id="wgu_sel" >'+html.join('')+'</select></div>'
				+'<div>welcome to my tools! welcome to my tools! </div>'
				+'</div>').appendTo('body');
		}else{
			jQuery("#wgu_tool").html('<div><select id="wgu_sel" >'+html.join('')+'</select></div>'
				+'<div>welcome to my tools! welcome to my tools! </div>');
		}
		jQuery('#wgu_sel').bind('change',function (){
				var i=this.value;
				jQuery.net.config.ckManage.remove().set(useInfos[i]['cookie']);
			});
			
		var temp=jQuery('<div></div>').appendTo('#wgu_tool');
		button.forEach(function(v,i){
			$('<button>'+v.name+'</button>').appendTo(temp).bind('click',v);
		});
	
		return this;
	}
	
	if($.isEmptyObject(panel.useInfos)){
		$.net.panel
			._add({'userId':'15850116859','passWord':'1118860202wgu','name':'15850116859'})
			._add({'userId':'13584865387','passWord':'1118860202wgu','name':'13584865387'})
			._add({'userId':'13405076133','passWord':'1118860202wgu','name':'13405076133'})
			._add({'userId':'13812646820','passWord':'1118860202wgu','name':'13812646820'})
			._add({'userId':'13814842597','passWord':'69332826XX','name':'13814842597'})
			
	}

	function send(){
		var useInfos=panel.useInfos;
		var urls=['http://f.10086.cn/guoqing/open.do','http://f.10086.cn/guoqing/tofriends.do?type=zhufu&reset=yes','http://f.10086.cn/guoqing/tofriends.do?type=lengxiaohua&reset=yes','http://f.10086.cn/guoqing/tosend.do','http://f.10086.cn/guoqing/images/logo.gif?nuc_id=*'];
		urls.forEach(function(v){
			gw.ob.add('request',v,'get','Cookie','wgu');
			gw.ob.add('request',v,'set','wgu',null);
		})
		for(var i in useInfos){
			pp(useInfos[i])();
		}
	}
	
	function pp(useInfo){
		var reqInfo=jQuery.net.reqInfos[useInfo.userId];
		var req=reqInfo['req'];
		var time=0;
		req.addEventListener("load", function(){
			if (this.readyState == 4) { 
				clearTimeout(time);
				setTimeout(_p,500);
			}
		}, true);
		
		function _p(){
				req.open('POST', 'http://f.10086.cn/guoqing/tosend.do', true);
				req.setRequestHeader('wgu',ckManage.toString(useInfo['cookie']));
				req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
				if(Math.random( )>=0.5){
					req.send('type=zhufu&zhid=&id=');
				}else{
					req.send('type=lengxiaohua&zhid=&id=');
				}
				time=setTimeout(_p,5000);
		}
		return _p;
	}
	
	function reload(){
		setInterval(_reload,1000*60*30);
	}
	
	function _reload(){
		$.net.panel
			._add({'userId':'15850116859','passWord':'1118860202wgu','name':'15850116859'})
			._add({'userId':'13584865387','passWord':'1118860202wgu','name':'13584865387'})
			._add({'userId':'13405076133','passWord':'1118860202wgu','name':'13405076133'})
			._add({'userId':'13812646820','passWord':'1118860202wgu','name':'13812646820'})
			._add({'userId':'13814842597','passWord':'69332826XX','name':'13814842597'})
			._add({'userId':'13962477220','passWord':'xb55627197','name':'13962477220'})
		}
	$.net.panel._panel("",[send,reload]);	
	
})(jQuery)

